//
//  OrderListCell.swift
//  Box
//
//  Created by mn on 2025/3/30.
//

import UIKit
import SnapKit

class OrderListCell: UITableViewCell {

    let productView = ProductView()
    let orderStateView = OrderStateView()
    let totalView = OrderStateView()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
        contentView.backgroundColor = .init(hex: "#F4F6F8")
        contentView.addSubview(orderStateView)
        contentView.addSubview(productView)
        contentView.addSubview(totalView)
        totalView.titleLabel.textColor = .init(hex: "#7D7D7D")
        totalView.titleLabel.font = .systemFont(ofSize: 13)
        totalView.statusLabel.textColor = .black
        totalView.statusLabel.font = .systemFont(ofSize: 13,weight: .semibold)


        orderStateView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(8)
            make.left.right.equalToSuperview()
            make.height.equalTo(42.5)
        }
        productView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(orderStateView.snp.bottom).offset(1)
        }
        totalView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(productView.snp.bottom).offset(1)
            make.height.equalTo(38.5)
            make.bottom.lessThanOrEqualToSuperview()
        }
    }
    
    func configure(with model: OrderModel) {
        orderStateView.titleLabel.text = ""
        orderStateView.statusLabel.text = model.statusDesc
        
        let price = String(format: "￥%.2f", Float(model.price) * 0.01)
        totalView.titleLabel.text = "共\(model.count)件商品"
        totalView.statusLabel.text = "实际支付 \(price)）"
        
        productView.productImageView.kf.setImage(with:URL(string:model.imageUrl))

        productView.titleLabel.text = model.goodsName
        productView.priceLabel.text = price

        productView.quantityLabel.text = "x\(model.count)"

    }
}
